package club.baimahu.pencil;

import club.baimahu.pencil.domain.entity.CommonBuyer;
import club.baimahu.pencil.domain.entity.Goods;
import club.baimahu.pencil.domain.entity.SuperMarketBuilder;
import club.baimahu.pencil.domain.session.GoodsStock;
import club.baimahu.pencil.domain.session.Supermarket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Arrays;


/**
 * 增加监听器模式,仓库自动检测某商品库存是否小于指定阈值,是的话将触发StockShortOfEvent事件,由监听该事件的listener处理
 * 将事件的发生与处理相分离
 */
public class Story3 {
    static Logger logger = LoggerFactory.getLogger(Story3.class);


    public static void main(String[] args) {
        CommonBuyer buyer = new CommonBuyer("小刚");
        buyer.addCacheAccount("000030011229999",new BigDecimal(100));

        SuperMarketBuilder superMarketBuilder = new SuperMarketBuilder();
        Supermarket supermarket = superMarketBuilder.province("浙江省")
                .city("杭州市")
                    .region("滨江区")
                        .detailAddress("长河街道江陵路111号")
                                .cacheAccount("1111125466667777",new BigDecimal(1000))
                                            .build("联华超市-滨江分店");

        logger.info("超市地址为{}",supermarket.getAddress());

        //进货
        Goods goods4 = new Goods("NO004","洗洁精",new BigDecimal(20),new BigDecimal(40));
        GoodsStock goodsStock = new GoodsStock(goods4,2);
        goodsStock.setBuyAmount(5);
        goodsStock.setMinAmount(2);
        supermarket.stockWithGoods(Arrays.asList(goodsStock));

        buyer.startShopping(supermarket);


        for(int j = 0 ; j <20 ; j++){
            buyer.buy("NO004",supermarket);
        }

        buyer.leave(supermarket);

    }
}
